import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ty_smart_watch/page/health/controller/common_controller.dart';

///日期选择条

class SelectDateBar extends StatefulWidget {
  final String title1;
  final String title2;
  final String title3;
  final Color color;

  const SelectDateBar(
      {super.key,
      required this.title1,
      required this.title2,
      required this.title3,
      required this.color});

  @override
  State<SelectDateBar> createState() => _SelectDateBarState();
}

class _SelectDateBarState extends State<SelectDateBar> {
  int index = 0;
  final CommonController _controller = Get.find();

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Expanded(
          child: InkResponse(
            splashColor: Colors.transparent, // 取消点击涟漪效果
            highlightColor: Colors.transparent, // 取消点击高亮效果（如果有的话）
            onTap: () {
              _controller.dateTypeIndex.value = 0;
              _controller.getDayBarList();
              _controller.getDayDetailList();
            },
            child: Item(
              title: widget.title1,
              color: widget.color,
              currentIndex: _controller.dateTypeIndex.value,
              itemIndex: 0,
            ),
          ),
        ),
        Expanded(
          child: InkResponse(
            splashColor: Colors.transparent, // 取消点击涟漪效果
            highlightColor: Colors.transparent, // 取消点击高亮效果（如果有的话）
            onTap: () {
              _controller.dateTypeIndex.value = 1;
              _controller.getWeeBarkList();
              _controller.getDayDetailList();
            },
            child: Item(
              title: widget.title2,
              color: widget.color,
              currentIndex: _controller.dateTypeIndex.value,
              itemIndex: 1,
            ),
          ),
        ),
        Obx(
          () => Expanded(
            child: InkResponse(
              splashColor: Colors.transparent, // 取消点击涟漪效果
              highlightColor: Colors.transparent, // 取消点击高亮效果（如果有的话）
              onTap: () {
                _controller.dateTypeIndex.value = 2;
                _controller.getMonthBarList();
                _controller.getDayDetailList();
              },
              child: Item(
                title: widget.title3,
                color: widget.color,
                currentIndex: _controller.dateTypeIndex.value,
                itemIndex: 2,
              ),
            ),
          ),
        ),
      ],
    );
  }
}

class Item extends StatelessWidget {
  Item({
    super.key,
    required this.title,
    required this.color,
    required this.currentIndex,
    required this.itemIndex,
  });

  final String title;
  final Color color;
  final int currentIndex;
  final int itemIndex;
  final CommonController _controller = Get.find();

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Text(title),
        Obx(
          () => Visibility(
            visible: _controller.dateTypeIndex.value == itemIndex,
            child: Container(
              height: 2,
              width: 16,
              color: color,
            ),
          ),
        ),
      ],
    );
  }
}
